﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.IO;
using System.Drawing.Imaging;
using System.Net;
using CarLoanSystem.Web.Comman;
using CarLoanSystem.DAL;
using CarLoanSystem.Entity;

namespace CarLoanSystemWeb.Page.EditProfile
{
    public partial class wuc_edit_profile_doc_donsman : UserControlManageForm
    {
        public event EventHandler InfoMessege;
        public event EventHandler ErrorMessege;
        private static BondsmanItem bondsmanItem;
        private static BondsmanDocItem bondsmanDocItem;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bondsmanItem = Session["Bondsman"] as BondsmanItem;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = FileUpload1.PostedFile.FileName; // getting the file path of uploaded file
                string filename1 = Path.GetFileName(filePath);     // getting the file name of uploaded file
                string ext = Path.GetExtension(filename1);          // getting the file extension of uploaded file

                if (FileUpload1.HasFile)
                {
                    Stream fs = FileUpload1.PostedFile.InputStream;
                    BinaryReader br = new BinaryReader(fs);  //reads the   binary files
                    Byte[] bytes = br.ReadBytes((Int32)fs.Length);  //counting the file length into bytes
                    bondsmanDocItem = new BondsmanDocItem();
                    bondsmanDocItem.BONDSMAN_ID = bondsmanItem.BONDSMAN_ID;
                    bondsmanDocItem.BONDSMAN_DOC_NAME = this.txtNameFile.Text;
                    bondsmanDocItem.BONDSMAN_DOC_FILE = bytes;
                    bondsmanDocItem.BONDSMAN_DOC_EXTENSION = ext;
                    BondsmanDocInfoDAL.Insert(bondsmanDocItem, bytes);
                    if (InfoMessege != null)
                    {
                        InfoMessege(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ErrorMessege != null)
                {
                    ErrorMessege(this, EventArgs.Empty);
                }
            }
        }
    }
}